package test

import bankofficegrepper.BankInfo
import groovy.xml.MarkupBuilder
import junit.framework.TestCase

/**
 * Created by IntelliJ IDEA.
 * User: janexie
 * Date: 2010-11-28
 * Time: 16:29:08
 * To change this template use File | Settings | File Templates.
 */
class CMBRetrieveDataTestCase extends TestCase {
  public void testRetriveData() throws Exception {
    def records = new XmlSlurper().parseText(source)
    List list = []
    def province = records.body.form.table[1].tbody.tr.td.table.tbody.tr[1].td.span[1].select.find {it.@name == "ddlProvince"}.option.findAll {it.@selected == "selected"}.text()
    def city = records.body.form.table[1].tbody.tr.td.table.tbody.tr[1].td.span[1].select.find {it.@name == "ddlCity"}.option.findAll {it.@selected == "selected"}.text()
    if (province == '')
      province = city
    def bankInfoRows = records.body.form.table[1].tbody.tr.td.table[2].tbody.tr.td.table.tbody.tr

    bankInfoRows = bankInfoRows[1..bankInfoRows.size() - 2]
    bankInfoRows.each {
      def bankInfoRow = it.td
      BankInfo info = new BankInfo();
      info.province = province
      info.city = city
      info.name = bankInfoRow[0]
      info.address = bankInfoRow[1]
      info.telephoneNo = bankInfoRow[2]
      info.serviceTime = bankInfoRow[3]
      list += info
    }
    println list.size()
    list.each {
      println 'Province: ' + it.getProvince() + ' City: ' + it.getCity() + ' Name :' + it.getName() + ' Address: ' + it.getAddress();
    }
  }

  public void ppstestTransfer() {
    List<BankInfo> bankinfoList = []
    BankInfo bankinfo = new BankInfo();
    bankinfo.name = 'yp'
    bankinfo.type = 'sh'

    BankInfo bankinfo2 = new BankInfo();
    bankinfo2.name = 'yp2'
    bankinfo2.type = 'sh2'
    bankinfoList += bankinfo;
    bankinfoList += bankinfo2;
    def writer = new StringWriter()
    def xml = new MarkupBuilder(writer);
    xml.bankinfos {
      bankinfoList.each {
        bankinfo = (BankInfo) it;
        xml.bankinfo {
          name(bankinfo.getName())
          type(bankinfo.getType())
          address(bankinfo.getAddress())
          city(bankinfo.getCity())
          province(bankinfo.getProvince())
          serviceTime(bankinfo.getServiceTime())
          telephoneNo(bankinfo.getTelephoneNo())
        }
      }
    }
    println writer.toString()
  }

  def source = """
<root><head>
		<title>招商银行营业网点一览表</title>





		<script language="JavaScript" src="../script/Common.js"></script>
<script src="http://www.cmbchina.com/cmb2005web/script/www_sdc.js"></script></head>
	<body ms_positioning="GridLayout">
		<form name="sub_list" method="post" action="subbranch_list.aspx" id="sub_list">




<script language="javascript" type="text/javascript">
<!--
	function __doPostBack(eventTarget, eventArgument) {
		var theform;
		if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
			theform = document.sub_list;
		}
		else {
			theform = document.forms["sub_list"];
		}
		theform.__EVENTTARGET.value = eventTarget.split("").join(":");
		theform.__EVENTARGUMENT.value = eventArgument;
		theform.submit();
	}
// -->
</script>


<script language="Javascript">
var SDC_js=document.createElement("script");
window.setTimeout('SDC_js.src="http://www.cmbchina.com/cmb2005web/script/www_sdc.js"',0);
var headElem=document.getElementsByTagName("head")[0];
headElem.appendChild(SDC_js);
</script>
<table class="black" cellspacing="0" cellpadding="0" width="618" bgcolor="#ffffff" border="0">
	<tbody><tr>
		<td><a href="http://www.cmbchina.com/" target="_blank"></a></td>
	</tr>
</tbody></table>
			<table class="black" cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
					<tr>
						<td valign="top" align="center" height="366">
							<table cellspacing="1" cellpadding="0" width="95%" align="middle" bgcolor="#000000" border="0">
								<tbody><tr bgcolor="#e0e0e0">
									<td colspan="4" height="30">
										<div class="20" align="center"><font color="#cc0000"><strong>营 业 网 点</strong></font></div>
									</td>
								</tr>
								<tr>
									<td valign="top" align="center" bgcolor="#f3f3f3"><span id="titleLabel" class="content">招商银行<font color="#B00000">包头</font>地区营业网点一览表 （更新日期：2010年01月06日）</span>
										<span class="content">省:<select name="ddlProvince" onchange="__doPostBack('ddlProvince','')" language="javascript" id="ddlProvince">
	<option selected="selected" value="">请选择省份</option>
	<option value="安徽">安徽</option>
	<option value="北京">北京</option>
	<option value="福建">福建</option>
	<option value="甘肃">甘肃</option>
	<option value="广东">广东</option>
	<option value="广西">广西</option>
	<option value="贵州">贵州</option>
	<option value="河北">河北</option>
	<option value="河南">河南</option>
	<option value="黑龙江">黑龙江</option>
	<option value="湖北">湖北</option>
	<option value="湖南">湖南</option>
	<option value="吉林">吉林</option>
	<option value="江苏">江苏</option>
	<option value="江西">江西</option>
	<option value="辽宁">辽宁</option>
	<option value="内蒙古">内蒙古</option>
	<option value="宁夏">宁夏</option>
	<option value="山东">山东</option>
	<option value="山西">山西</option>
	<option value="陕西">陕西</option>
	<option value="上海">上海</option>
	<option value="四川">四川</option>
	<option value="天津">天津</option>
	<option value="新疆">新疆</option>
	<option value="云南">云南</option>
	<option value="浙江">浙江</option>
	<option value="重庆">重庆</option>

</select>
											市:<select name="ddlCity" onchange="__doPostBack('ddlCity','')" language="javascript" id="ddlCity">
	<option value="">请选择城市</option>
	<option selected="selected" value="包头">包头</option>
	<option value="北京">北京</option>
	<option value="长春">长春</option>
	<option value="长沙">长沙</option>
	<option value="常熟">常熟</option>
	<option value="常州">常州</option>
	<option value="成都">成都</option>
	<option value="慈溪">慈溪</option>
	<option value="大连">大连</option>
	<option value="丹东">丹东</option>
	<option value="东莞">东莞</option>
	<option value="鄂尔多斯">鄂尔多斯</option>
	<option value="佛山">佛山</option>
	<option value="福州">福州</option>
	<option value="福州福清">福州福清</option>
	<option value="赣州">赣州</option>
	<option value="广州">广州</option>
	<option value="贵阳">贵阳</option>
	<option value="哈尔滨">哈尔滨</option>
	<option value="杭州">杭州</option>
	<option value="合肥">合肥</option>
	<option value="衡阳">衡阳</option>
	<option value="呼和浩特">呼和浩特</option>
	<option value="湖州">湖州</option>
	<option value="淮南">淮南</option>
	<option value="黄石">黄石</option>
	<option value="惠州">惠州</option>
	<option value="即墨">即墨</option>
	<option value="济南">济南</option>
	<option value="嘉兴">嘉兴</option>
	<option value="江阴">江阴</option>
	<option value="金华">金华</option>
	<option value="九江">九江</option>
	<option value="昆明">昆明</option>
	<option value="昆山">昆山</option>
	<option value="兰州">兰州</option>
	<option value="乐山">乐山</option>
	<option value="丽江">丽江</option>
	<option value="临沂">临沂</option>
	<option value="洛阳">洛阳</option>
	<option value="绵阳">绵阳</option>
	<option value="南昌">南昌</option>
	<option value="南京">南京</option>
	<option value="南宁">南宁</option>
	<option value="南通">南通</option>
	<option value="宁波">宁波</option>
	<option value="盘锦">盘锦</option>
	<option value="青岛">青岛</option>
	<option value="曲靖">曲靖</option>
	<option value="衢州">衢州</option>
	<option value="泉州">泉州</option>
	<option value="泉州晋江">泉州晋江</option>
	<option value="泉州石狮">泉州石狮</option>
	<option value="日照">日照</option>
	<option value="上海">上海</option>
	<option value="绍兴">绍兴</option>
	<option value="深圳">深圳</option>
	<option value="沈阳">沈阳</option>
	<option value="石家庄">石家庄</option>
	<option value="苏州">苏州</option>
	<option value="太原">太原</option>
	<option value="泰州">泰州</option>
	<option value="天津">天津</option>
	<option value="威海">威海</option>
	<option value="潍坊">潍坊</option>
	<option value="温州">温州</option>
	<option value="乌鲁木齐">乌鲁木齐</option>
	<option value="无锡">无锡</option>
	<option value="芜湖">芜湖</option>
	<option value="武汉">武汉</option>
	<option value="西安">西安</option>
	<option value="厦门">厦门</option>
	<option value="湘潭">湘潭</option>
	<option value="襄阳">襄阳</option>
	<option value="孝感">孝感</option>
	<option value="烟台">烟台</option>
	<option value="扬州">扬州</option>
	<option value="宜昌">宜昌</option>
	<option value="宜兴">宜兴</option>
	<option value="银川">银川</option>
	<option value="榆林">榆林</option>
	<option value="张家港">张家港</option>
	<option value="镇江">镇江</option>
	<option value="郑州">郑州</option>
	<option value="中山">中山</option>
	<option value="重庆">重庆</option>
	<option value="株洲">株洲</option>
	<option value="诸暨">诸暨</option>
	<option value="淄博">淄博</option>

</select>
											关键字:</span>

									</td>
								</tr>
							</tbody></table>
							<table cellspacing="0" cellpadding="0" width="95%" align="middle" bgcolor="#000000" border="0">
								<tbody><tr bgcolor="#cc0000">
									<td colspan="4" height="2"></td>
								</tr>
							</tbody></table>
								<table cellspacing="1" cellpadding="0" width="95%" align="middle" bgcolor="#000000" border="0">
								<tbody><tr bgcolor="#e0e0e0">
									<td>
							<table class="content" cellspacing="0" cellpadding="2" rules="all" bordercolor="Black" border="0" id="subDataGrid" bgcolor="White" width="100%">
	<tbody><tr bgcolor="#EFEFEF">
		<td width="20%"><font face="Verdana" color="#000040"><b>网点名称</b></font></td><td width="30%"><font face="Verdana" color="#000040"><b>地址</b></font></td><td width="15%"><font face="Verdana" color="#000040"><b>储蓄电话</b></font></td><td width="25%"><font face="Verdana" color="#000040"><b>储蓄营业时间</b></font></td><td width="10%"><font face="Verdana" color="#000040"><b>网点地图</b></font></td>
	</tr><tr>
		<td><font face="Verdana" color="#000040">招商银行包头支行                                                                                                                                                                                                                                               </font></td><td><font face="Verdana" color="#000040">包头市钢铁大街甲5号（电视台对面西北角）                                                                                                                                                                                                                        </font></td><td><font face="Verdana" color="#000040">0472-5338600                                                                                                                                                                                                                                                   </font></td><td><font face="Verdana" color="#000040">8：30-18：00                                                                                                                                                                                                                                                   </font></td><td><font face="Verdana" color="#000040"><a class="bluelink" href="#" onclick="javascript:go2map('包头','招商银行包头支行');">查看gt;gt;</a></font></td>
	</tr><tr>
		<td colspan="6"><font face="Verdana" color="#000040"><span>1</span></font></td>
	</tr>
</tbody></table>
							</td>
							</tr>
							</tbody></table>
						</td>
					</tr>
				</tbody>
			</table>
		</form>


</body></root> """
}
